// pages/manage/manage.js
const db = wx.cloud.database()
const app = getApp()

Page({
  data: {
    addresses: []
  },
  onLoad() {
    this.getAddress()
  },
  onShow: function() {
    if (app.globalData.flushManage) {
      app.globalData.flushManage = false
      this.getAddress()
    }
  },
  getAddress() {
    let that = this
    let groupId = null
    if (app.globalData.group) {
      groupId = app.globalData.group._id
    }
    wx.cloud.callFunction({
      name: 'getAddress',
      data: {
        groupId: groupId
      }
    }).then(res => {
      that.setData({
        addresses: res.result
      })
    })
  },
  editAddress: function(e) {
    var address = e.currentTarget.dataset.address
    wx.navigateTo({
      url: '/pages/manage_edit/manage_edit?address=' + JSON.stringify(address),
      success: function(res) {},
      fail: function(res) {},
      complete: function(res) {},
    })
  },
  addAddress() {
    // 点击去跳转到list页面
    wx.navigateTo({
      url: '/pages/manage_edit/manage_edit',
      success: function(res) {
        console.log("成功")
      },
      fail: function(res) {
        console.log("失败")
      },
      complete: function(res) {},
    })
  }
})